package com.changgou.goods.dao;

import com.changgou.goods.pojo.Category;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface CategoryMapper extends Mapper<Category> {

    @Select("select * from tb_category where parent_id = 0")
    @Results({
            @Result(column = "id",property = "id",id = true),
            @Result(property = "children",column = "id",many = @Many(select = "com.changgou.goods.dao.CategoryMapper.findChildren1"))
    })
    List<Category> findCategory();

    @Select("select * from tb_category where parent_id = #{id}")
    @Results({
            @Result(column = "id",property = "id",id = true),
            @Result(property = "children",column = "id",many = @Many(select = "com.changgou.goods.dao.CategoryMapper.findChildren2"))
    })
    List<Category> findChildren1();

    @Select("select * from tb_category where parent_id = #{id}")
    List<Category> findChildren2();
}
